﻿using Travel.Data.Inputs;
using Travel.Data;
using Microsoft.AspNetCore.Mvc;
using Travel.API.Filters;
using Travel.Data.Consts;
using Travel.Data.Dtos;
using Travel.Service.User;

namespace Travel.API.Controller
{
    /// <summary>
    /// 菜单按钮相关服务
    /// </summary>
    [ApiController]
    [Route("[controller]/[action]")]
    public class MenuButtonController : BaseController
    {
        private readonly IMenuButtonService _menuButtonService;

        public MenuButtonController(IMenuButtonService menuButtonService)
        {
            _menuButtonService = menuButtonService;
        }
        /// <summary>
        /// 添加或者修改 菜单按钮
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        [HttpPost]
        public async Task<Results<int>> UpdateOrAdd([FromBody]MenuButtonInput input)
        {
            return await _menuButtonService.UpdateOrAdd(input);
        }

        /// <summary>
        /// 菜单按钮查询
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        [HttpPost]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<PageDto<MenuButtonDto>>> MenuButtonQuery([FromBody]MenuButtonQueryInput input) 
        { 
            
            return await _menuButtonService.MenuButtonQuery(input);
        }

        /// <summary>
        /// 根据菜单按钮ID获取一条记录
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet("{id}")]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
        public async Task<Results<MenuButtonDto>> GetMenuButtonById(long id) { 
         return await _menuButtonService.GetMenuButtonById(id);
        }

        /// <summary>
        /// 批量删除
        /// </summary>
        /// <param name="loginUserId"></param>
        /// <param name="idList"></param>
        /// <returns></returns>
        [HttpDelete]
        [TravelAuthorize(AuthorizeRoleName.Administrator)]
       public async Task<Results<int>> RemoveMenuButton([FromBody]List<long> idList) {

            return await _menuButtonService.RemoveMenuButton(idList.ToArray());
        }
    }
}
